package com.forclass;

import java.io.*;

public class MyFileClassloader extends ClassLoader{
    private static final String CLASS_FILE_PATH = "D:\\FileIo\\Message.class";

    public Class<?> loadData(String className) throws Exception {
        byte data[] = this.loadFileClassData();
        if (data != null) {
            return super.defineClass(className,data,0,data.length);
        }
        return null;
    }

    public byte[] loadFileClassData() throws Exception {
        InputStream input = new FileInputStream(new File(CLASS_FILE_PATH));
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        input.transferTo(bos);
        byte data[] = bos.toByteArray();
        input.close();
        return data;
    }
}
